Skip to content

refactor(engine): encapsulate Context VM field access behind wrapper methods#5149

Open
hansl wants to merge 3 commits intoboa-dev:mainfrom
hansl:split-context-step-1
Open

refactor(engine): encapsulate Context VM field access behind wrapper methods#5149
hansl wants to merge 3 commits intoboa-dev:mainfrom
hansl:split-context-step-1

Conversation

@hansl
Copy link
Contributor

@hansl hansl commented Mar 19, 2026

Add context/vm_access.rs with 45 wrapper methods that delegate to Context's internal Vm field, then replace all ~600 direct context.vm.* accesses across 78 files with calls to these wrappers.

This is the first step toward extracting Context into its own crate (boa_context). By routing all external access through methods, the internal structure of Context can be changed without touching call sites.

…methods

Add `context/vm_access.rs` with 45 wrapper methods that delegate to
`Context`'s internal `Vm` field, then replace all ~600 direct
`context.vm.*` accesses across 78 files with calls to these wrappers.

This is the first step toward extracting Context into its own crate
(boa_context). By routing all external access through methods, the
internal structure of Context can be changed without touching call sites.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@hansl hansl requested review from a team, jedel1043 and nekevss as code owners March 19, 2026 05:07
@github-actions github-actions bot added the Waiting On Review Waiting on reviews from the maintainers label Mar 19, 2026
@github-actions github-actions bot added this to the v1.0.0 milestone Mar 19, 2026
@github-actions github-actions bot added C-Builtins PRs and Issues related to builtins/intrinsics C-VM Issues and PRs related to the Boa Virtual Machine. C-Intl Changes related to the `Intl` implementation labels Mar 19, 2026
@github-actions
Copy link

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 50,073 50,073 0
Ignored 2,072 2,072 0
Failed 818 818 0
Panics 0 0 0
Conformance 94.54% 94.54% 0.00%

Tested main commit: 055ee0958ce332f3f99af27536a7c6f9a91def27
Tested PR commit: 498b424578252944cbbfae90753e73f8c15149ae
Compare commits: 055ee09...498b424

@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 76.82737% with 149 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.80%. Comparing base (6ddc2b4) to head (5f81e48).
⚠️ Report is 917 commits behind head on main.

Files with missing lines Patch % Lines
core/engine/src/object/builtins/jspromise.rs 0.00% 16 Missing ⚠️
core/engine/src/builtins/proxy/mod.rs 0.00% 11 Missing ⚠️
core/engine/src/vm/opcode/call/mod.rs 47.36% 10 Missing ⚠️
core/engine/src/vm/opcode/iteration/iterator.rs 61.53% 10 Missing ⚠️
core/engine/src/vm/opcode/environment/mod.rs 67.85% 9 Missing ⚠️
core/engine/src/vm/opcode/define/class/setter.rs 20.00% 8 Missing ⚠️
core/engine/src/vm/opcode/set/private.rs 20.00% 8 Missing ⚠️
core/engine/src/vm/opcode/set/property.rs 66.66% 8 Missing ⚠️
core/engine/src/vm/opcode/control_flow/jump.rs 76.66% 7 Missing ⚠️
core/engine/src/vm/opcode/push/class/private.rs 0.00% 7 Missing ⚠️
... and 23 more
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5149       +/-   ##
===========================================
+ Coverage   47.24%   59.80%   +12.55%     
===========================================
  Files         476      583      +107     
  Lines       46892    63496    +16604     
===========================================
+ Hits        22154    37971    +15817     
- Misses      24738    25525      +787     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jedel1043 jedel1043 added the A-Technical Debt Changes related to technical debt label Mar 19, 2026
}

let in_with = context.vm.frame().environments.has_object_environment();
let in_with = context.frame().environments.has_object_environment();
Copy link
Member

@jedel1043 jedel1043 Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this shows we would also need to extract the environment related types, but those depend on JsObject, so...

Maybe we should start by extracting JsObject first?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And JsObject depends on Context.

Regardless, this PR would still be needed. And it's a simple refactor, there should be no behaviour changes. I can do a follow to address the environment types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this doesn't block merging this, but we also need to think what exactly are the steps to properly extract this into its own crate

@github-actions
Copy link

github-actions bot commented Mar 19, 2026

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 50,545 50,545 0
Ignored 1,426 1,426 0
Failed 992 992 0
Panics 2 2 0
Conformance 95.43% 95.43% 0.00%

Tested main commit: 5b0f62ad860a2f5e2a4631ac2f280642cf7e21ea
Tested PR commit: 5f81e483eb7071ee6423c65fbb2f1f050085edac
Compare commits: 5b0f62a...5f81e48

@jedel1043 jedel1043 removed the C-Builtins PRs and Issues related to builtins/intrinsics label Mar 20, 2026
@github-actions github-actions bot added the C-Builtins PRs and Issues related to builtins/intrinsics label Mar 23, 2026

/// Pop a value from the VM stack.
#[track_caller]
pub(crate) fn stack_pop(&mut self) -> JsValue {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to have individual methods to pop and push from the stack here? I would expect that just returning &mut Stack should be enough

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same approach we follow for the EnvironmentStack, so it makes sense to also use the same approach here.


impl Context {
/// Get the loop iteration limit.
pub(crate) fn loop_iteration_limit(&self) -> u64 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same suggestion here. We should return &RuntimeLimits instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Technical Debt Changes related to technical debt C-Builtins PRs and Issues related to builtins/intrinsics C-Intl Changes related to the `Intl` implementation C-VM Issues and PRs related to the Boa Virtual Machine. Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants